<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xml:lang="en" lang="en">
	<h:head />
	<body>
		<ui:composition template="/rootWeb.xhtml">
	    <ui:define name="header">
	        <title>协议管理</title>
	        <script type="text/javascript">
				//页面载入时注册
	        	jQuery(document).ready(function(){
	        		//鼠标移入
					jQuery("#agreementListTable_data tr").live("mouseover", function() {
					  	jQuery(this).css("background-color","#CCCCCC");
					});
					//鼠标移出
					jQuery("#agreementListTable_data tr").live("mouseout", function() {
					  	jQuery(this).css("background-color","white");
					});
				});
				//重置
				function resetQueryCondition(){
					jQuery("#queryAgreementCode").val("");
					jQuery("#queryAgreementState").val("");
					jQuery("#queryCustomer").val("");
					jQuery("#queryAgreementCreateDate_input").val("");
				}
			</script>
			<style type="text/css">
				
			</style>
		</ui:define>
	    <ui:define name="body">
	    	<h:form id="form" prependId="false">
	    		<div style="white-space:nowrap;width: 100%;overflow:inherit;"> 
	    		<h:panelGrid  columns="6" style="width: 100%" >
					<h:outputLabel for="queryAgreementCode" value="协议编号：" />
					<p:inputText id="queryAgreementCode" value="#{agreementManageAction.queryAgreementMain.agreementCode}"  size="15"/>
					<h:outputLabel for="queryAgreementCreateDate" value="协议日期："/>
    				<p:calendar id="queryAgreementCreateDate" value="#{agreementManageAction.queryAgreementMain.createDate}" size="15"
    					timeZone="GMT+8" pattern="yyyy-MM-dd" showButtonPanel="true" navigator="true"/>
    				<h:outputLabel for="queryCustomer" value="客户："/>
		    		<p:inputText id="queryCustomer" value="#{agreementManageAction.queryAgreementMain.customer.customerName}" />
		    		<p:commandButton  value="选择" action="#{agreementManageAction.queryCustomerList('query')}"
		    		        oncomplete="selectCustomerDlg.show();" update=":form:selectCustomerTable"/>	
					<h:outputLabel for="queryAgreementState" value="协议状态：" />
    				<h:selectOneMenu id="queryAgreementState" value="#{agreementManageAction.queryAgreementMain.agreementState}" style="width: 170px;height:25px;font-size: 17.6px">  
    				 	<f:selectItem itemLabel="请选择"  itemValue=""/>
		                <f:selectItems value="#{agreementManageAction.agreementStateItems}"/>
		            </h:selectOneMenu>
    				<p:spacer/><p:spacer/>
    				<h:panelGrid columns="2">
	   				    <p:commandButton value="查询" action="#{agreementManageAction.doFilterAgreementList}"  update=":form:agreementListTable"/>
	    				<p:commandButton value="重置" onclick="resetQueryCondition()" />
    				</h:panelGrid>
    				<h:panelGrid columns="2"> 
    				    <p:commandButton value="新增" action="#{agreementManageAction.addAgreement}" update=":form:addAgreementDlgID" oncomplete="addAgreementDlg.show()"/>
	    			    <p:commandButton value="导入导出"/>
    			    </h:panelGrid>
				</h:panelGrid><p/>
				<p:dataTable id="agreementListTable" value="#{agreementManageAction.agreementMainList}" var="agreement" rowKey="#{agreement}" emptyMessage="没有协议！"
	    				paginator="true" rows="10"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="false" 	paginatorPosition="bottom" currentPageReportTemplate="查询到{totalRecords}条记录，本页显示{startRecord}～{endRecord}；第{currentPage}/{totalPages}页"
               			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"   >
               			<f:facet name="header">协议列表</f:facet>
               			<p:column headerText="协议号">#{agreement.agreementCode}</p:column>
               			<p:column headerText="客户">
               			    <h:outputText  value="#{agreement.customer.customerName}"/>
               			</p:column>
               			<p:column headerText="基础铝价">
               			    <h:selectOneMenu id="priceType" value="#{agreement.alprice.priceType}" disabled="true" >  
		                        <f:selectItems value="#{agreementManageAction.alpriceTypeItems}"/>
		                    </h:selectOneMenu>
               			</p:column>
               			<p:column headerText="预付比例"  style="text-align:right;">
               				<h:outputText value="#{agreement.advanceRatio}"  >
               					<f:convertNumber type="number" pattern="#,###.##" minFractionDigits="2"/>
               				</h:outputText>
               			</p:column>
               			<p:column headerText="协议状态" >
               				<h:selectOneMenu value="#{agreement.agreementState}" disabled="true">  
					            <f:selectItems value="#{agreementManageAction.agreementStateItems}"/>
					         </h:selectOneMenu>
						</p:column>
               			<p:column headerText="签约日期">
               				<h:outputText value="#{agreement.createDate}" >
               					<f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8" />
               				</h:outputText>
               			</p:column>
               			<p:column headerText="操作">
               				<p:commandLink value="查看" action="#{agreementAction.viewAgreement(agreement)}" style="color:RED" >
	    				    </p:commandLink>
	    				    <p:commandLink value="修改" action="#{agreementAction.updateAgreement(agreement)}" style="color:RED" >
	    				    </p:commandLink>
	    				    <p:commandLink value="删除" action="#{agreementAction.delectAgreement(agreement)}" style="color:RED"  >
	    				    </p:commandLink>
               			</p:column>
               	</p:dataTable>
               	
               	
               	<!-- 新增协议 -->
               	<p:dialog id="addAgreementDlgID" header="新增协议" widgetVar="addAgreementDlg" modal="true" resizable="true" >
               		<p:outputPanel id="addAgreementMainPanel"  style="width: 100%" >
              			<table><tr><td>
							<h:outputLabel for="addAgreementCreateDate" value="签约日期："/>
						</td><td>
							<h:inputText id="addAgreementCreateDate" value="#{agreementManageAction.addAgreementMain.createDate}" >
               					<f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8" />
               				</h:inputText>
               			</td><td>
	              			<h:outputLabel for="addAgreementCode" value="协议编号："/>
	              		</td><td>
					    	<h:inputText id="addAgreementCode"  value="#{agreementManageAction.addAgreementMain.agreementCode}" styleClass="outputInfoFont" />
					    </td><td>
               				<h:outputLabel rendered="false" for="addAgreementCustomerName" value="签约客户："/>
               			</td><td>
					    	<p:inputText id="addCustomer" value="#{agreementManageAction.addAgreementMain.customer.customerName}" />
		    		        <p:commandButton  value="选择" action="#{agreementManageAction.queryCustomerList('add')}"
		    		        oncomplete="selectCustomerDlg.show();" update=":form:selectCustomerTable"/>
					    </td></tr>
					    <tr><td>
               				<h:outputLabel for="addAlPrice" value="基础铝价："/>
               			</td><td>
					    	<h:selectOneMenu id="addAlPrice" value="#{agreementManageAction.addAgreementMain.alpriceType}" >  
		                        <f:selectItems value="#{agreementManageAction.alpriceTypeItems}"/>
		                    </h:selectOneMenu>
		                </td><td>
               				<h:outputLabel for="addAdvanceRatio" value="预付比例："/>
               			</td><td>
					    	<p:inputText id="addAdvanceRatio"  value="#{agreementManageAction.addAgreementMain.advanceRatio}"  style="font-weight: bold;width:160px;text-align:right;ime-mode:disabled" 
					    			onfocus="replaceComma(id,value);" onkeyup="checkMoneyOnKeyUp(this.id, this.value, 20, 2)" >
					    		 <f:convertNumber type="number" pattern="#,###.##" minFractionDigits="2"/>
					    	</p:inputText>              				
					    </td><td>
               				<h:outputLabel for="addAgreementState" value="是否有效："/>
               			</td><td>
               				<h:selectOneMenu id="addAgreementState" value="#{agreementManageAction.addAgreementMain.agreementState}" style="font-weight: bold;width:160px" >  
					            <f:selectItems value="#{agreementManageAction.agreementStateItems}"/>
					        </h:selectOneMenu>
					     </td></tr>
					     <tr><td >
						    <h:outputLabel for="addAgreementDesc" value="备注："/>
						 </td><td colspan="5">
						    <p:inputTextarea id="addAgreementDesc" value="#{agreementManageAction.addAgreementMain.agreementDesc}" rows="3" autoResize="false"  
						         maxlength="100" style="width:700px" />
						 </td></tr></table>
               		</p:outputPanel><p/>
               		<div style="overflow: auto">
               		<p:dataTable id="addAgreementDetailTable" value="#{agreementManageAction.addAgreementDetailList}" var="addAgreementDetail" rowKey="#{addAgreementDetail}" emptyMessage="没有记录！"
               			 rowIndexVar="rowIndex"
	    				paginator="true" rows="5"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="false" 	paginatorPosition="bottom" currentPageReportTemplate="{currentPage} / {totalPages}"
               			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"   >
               			<p:column selectionMode="multiple" />
               			<p:column headerText="" style="width:10px">#{rowIndex+1}</p:column>
               			<p:column headerText="条款类型">
               				<h:selectOneMenu id="addArticleType" value="#{addAgreementDetail.articleType}" style="width:60px">  
				                <f:selectItems value="#{agreementManageAction.articleTypeItems}"/>
				                <p:ajax event="change" listener="#{agreementManageAction.doChangeArticleDetail(addArticleType)}"   update=":form:addArticleDetail"/>
				            </h:selectOneMenu>
               			</p:column>
               			<p:column headerText="条款明细" style="width:80px">
		    				<h:selectOneMenu id="addArticleDetail" value="#{addAgreementDetail.articleDetail}" style="width:60px">  
				                <f:selectItems value="#{agreementManageAction.articleDetailItems}"/>
				            </h:selectOneMenu>
		    			</p:column>
               			<p:column headerText="加工费单价">
               				<p:inputText  id="addArticlePrice" value="#{addAgreementDetail.articlePrice}"  style="width:50px;text-align:right" readonly="true" 
               				      onfocus="replaceComma(id,value);" onkeyup="checkMoneyOnKeyUp(this.id, this.value, 20, 2)" >
					    		 <f:convertNumber type="number" pattern="#,###.##" minFractionDigits="2"/>
					    	</p:inputText>
               			</p:column>
		    			<f:facet name="footer">
		    				<p:commandButton value="添加"  action="#{agreementManageAction.addAgreementDetail('add')}" update=":form:addAgreementDetailTable"/><p:spacer width="5"/>
		    				<p:commandButton value="删除" action="#{agreementManageAction.deleteAgreementDetail('add')}" update=":form:addAgreementDetailTable"
		    					oncomplete="if(this.args.error){alert(this.args.error)}"/>
		    			</f:facet>
               		</p:dataTable>
               		</div>
               		<f:facet name="footer">
		    				<p:commandButton value="保存" action="#{agreementManageAction.saveAgreement('add')}"  update=":form:agreementListTable"
		    					oncomplete="if(this.args.error){alert(this.args.error)}else{alert(this.args.msg);addAgreementDlg.hide();}" />
		    				<p:spacer width="5"/>
		    				<p:commandButton value="关闭" onclick="addAgreementDlg.hide();" type="button"/>
		    			</f:facet>
               	</p:dialog>
              
               	<!-- 选择客户 -->
               	<p:dialog id="selectCustomerDlgID" header="选择客户" widgetVar="selectCustomerDlg" modal="true" resizable="false" >
               			<h:panelGrid  columns="3" style="width: 100%" >
					       <h:outputLabel for="queryCustomerName" value="客户名称：" />
					       <p:inputText id="queryCustomerName" value="#{agreementManageAction.queryCustomerName}"  size="15"/>
	   				       <p:commandButton value="查询" action="#{agreementManageAction.doFilterCustomerList}"  update=":form:selectCustomerTable"/>
    				    </h:panelGrid>
               			<p:dataTable id="selectCustomerTable" value="#{agreementManageAction.customerList}" var="customer" rowKey="#{customer}" emptyMessage="没有客户！"
               				selection="#{agreementManageAction.selectedCustomer}"
		    				paginator="true" rows="10"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="false" 	paginatorPosition="bottom" currentPageReportTemplate="{currentPage} / {totalPages}"
	               			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"   >	
	               		    <p:column selectionMode="single"/>
	               		    <p:column headerText="客户编号">
	               			    <h:outputText value="#{customer.customerCode}"/>
	               		    </p:column>
               			    <p:column headerText="客户名称">
               				    <h:outputText value="#{customer.customerName}"/>
               			    </p:column>
               			    <p:column headerText="客户公司">
               				    <h:outputText value="#{customer.customerCompany}"/>
               			    </p:column>
               			    <p:column headerText="客户备注">
               				    <h:outputText value="#{customer.customerDesc}"/>
               			    </p:column>
	               		</p:dataTable>
	               		<f:facet name="footer">
		    				<p:commandButton value="确定" action="#{agreementManageAction.selectCustomer}"
		    					update=":form:queryCustomer, :form:addCustomer" oncomplete="selectCustomerDlg.hide();"/>
		    				<p:commandButton value="取消" oncomplete="selectCustomerDlg.hide()"/>
		    			</f:facet>
               	</p:dialog>
               	</div>
			</h:form>
	    </ui:define>
		</ui:composition>
	</body>
</html>